#include<iostream>
using namespace std;
#include<sys/types.h>
#include<unistd.h>
#include<vector>
const int num = 10;


void RunSubProcess()
{
    while(true)
    {
        sleep(1);
        cout<<"i am a subprocess,pid:" << getpid() << " ppid:" << getppid() << endl;
    }
}
int main()
{
    vector<pid_t> childs;
    for(int i=0; i<num; i++)
    {
        pid_t id = fork();
        
        if(id == 0)
        {
            //子进程运行死循环的函数
            RunSubProcess();
        }

        //只有父进程会来到这
        childs.push_back(id);
    }

    cout<<"我是父进程，pid:" << getpid() << " ppid:" << getppid()<<endl;
    cout<<"我的孩子进程是：";
    for(auto child : childs)
    {
        cout << child << " ";
    }
    cout<<endl;
    sleep(10);
    while(true)
    {
        cout<<"我是父进程，pid:" << getpid() << " ppid:" << getppid()<<endl;
        sleep(1);
    }


}
